package com.gameShare.controller.misc

import com.gameShare.controller.base.LoginVerifyController
import com.gameShare.entity.dto.misc.MessageDto
import com.gameShare.entity.vo.ResponseVo
import com.gameShare.service.misc.MessageService
import jakarta.servlet.http.HttpServletRequest
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("message")
class MessageController(
    private val messageService: MessageService
) : LoginVerifyController() {

    /**
     * 通过用户id获取消息列表
     *
     * @param httpServletRequest 传递token
     * @param type 消息类型
     * @return
     */
    @RequestMapping("getMessageList")
    fun getMessageList(httpServletRequest: HttpServletRequest, type : Int?): ResponseVo<List<MessageDto>?> {
        return getSuccessResponseVO(
            messageService.getMessageList(getUserIdByToken(httpServletRequest), type)
        )
    }

    /**
     * 读消息
     *
     * @param httpServletRequest 传递token
     * @param messageId 读取
     * @return
     */
    @RequestMapping("readMessage")
    fun readMessage(httpServletRequest: HttpServletRequest, messageId : Int): ResponseVo<Boolean> {
        return getSuccessResponseVO(messageService.readMessage(
            getUserIdByToken(httpServletRequest),
                messageId
            )
        )
    }

    /**
     * 读取所有消息通过消息类型
     *
     * @param httpServletRequest 传递token
     * @param type 消息类型
     * @return
     */
    @RequestMapping("readAllMessage")
    fun readAllMessage(httpServletRequest: HttpServletRequest, type: Int): ResponseVo<Boolean> {
        return getSuccessResponseVO(
            messageService
                    .readAllMessage(
                        getUserIdByToken(httpServletRequest),
                        type
            )
        )
    }

    /**
     * 删除消息通过消息id
     *
     * @param httpServletRequest 传递token
     * @param messageId 消息id
     * @return
     */
    @RequestMapping("delMessage")
    fun delMessage(httpServletRequest: HttpServletRequest, messageId: Int): ResponseVo<Boolean> {
        return getSuccessResponseVO(
            messageService.delMessage(
                getUserIdByToken(httpServletRequest),
                messageId
            )
        )
    }

    /**
     * 删除所有消息通过类型
     *
     * @param httpServletRequest 传递token
     * @param type 消息类型
     * @return
     */
    @RequestMapping("delAllMessage")
    fun delAllMessage(httpServletRequest: HttpServletRequest, type: Int): ResponseVo<Boolean> {
        return getSuccessResponseVO(
            messageService.delAllMessage(
                getUserIdByToken(httpServletRequest), type
            )
        )
    }

}